package com.hxl.tech.gateway.auth.controller;


import com.hxl.tech.gateway.auth.annotate.ApiPrivilege;
import com.hxl.tech.gateway.auth.dto.Response;
import com.hxl.tech.gateway.auth.util.AppInitUtil;
import com.hxl.tech.gateway.common.constant.AppConstant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 短信 Controller
 * @author soliddq
 * @date 2023-10-10
 */
@Api(value = "刷新应用", tags = "刷新应用")
@RestController
@RequiredArgsConstructor
public class InitController {

    private final AppInitUtil appInitUtil;

    @ApiPrivilege(needRole = AppConstant.ROLE_ADMIN)
    @GetMapping("gateway.auth.openurl.refresh")
    @ApiOperation(value = "刷新开放接口地址", response = void.class)
    public Response freshOpenUrl() {

        appInitUtil.freshOpenUrl();
        return Response.createSuccess();
    }

    @ApiPrivilege(needRole = AppConstant.ROLE_ADMIN)
    @GetMapping("gateway.auth.application.refresh")
    @ApiOperation(value = "刷新开放应用", response = void.class)
    public Response freshApplication() {

        appInitUtil.freshApplication();
        return Response.createSuccess();
    }

    @ApiPrivilege(needRole = AppConstant.ROLE_ADMIN)
    @GetMapping("gateway.auth.api.refresh")
    @ApiOperation(value = "刷新开放接口名称", response = void.class)
    public Response freshApi() {

        appInitUtil.freshApi();
        return Response.createSuccess();
    }

    @ApiPrivilege(needRole = AppConstant.ROLE_ADMIN)
    @GetMapping("gateway.auth.limit.refresh")
    @ApiOperation(value = "刷新网关限流策略", response = void.class)
    public Response freshLimitRule() {

        appInitUtil.freshLimitIp();
        appInitUtil.freshLimitRate();
        return Response.createSuccess();
    }


    @ApiPrivilege(needRole = AppConstant.ROLE_ADMIN)
    @GetMapping("gateway.auth.api.approval.refresh")
    @ApiOperation(value = "刷新网关接口授权", response = void.class)
    public Response freshApiApproval() {

        appInitUtil.freshApiApproval();
        return Response.createSuccess();
    }

}
